<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>

   function Employee(name){
       this.name= name;
   }

   Employee.prototype.sayHello=function () {
       alert('hello:'+this.name);
   }

   var  emp1 = new Employee("Mark");
  // emp1.sayHello();



   /***
    * 1. 原型链继承
    * */


 /*  function SuperType() {
       this.colors=[];
       this.info = function () {
           alert("this is a superType");
       }
   }

   function SubType() {

   }
   SubType.prototype=new SuperType();
   var sub1 = new SubType();
  console.log(sub1.colors)  ;
  sub1.info();*/


 /***
  * 2.借用构造器继承
  * */

 function SuperType() {

     this.colors = [];
     this.info=function () {
         alert("this is a superType")
     }
 }

 function SubType() {
     SuperType.call(this);
 }

 var instance1 = new SubType();
 instance1.colors.push('red');
 console.log(instance1.colors);
 instance1.info();

   var instance2 = new SubType();
   instance2.colors.push('green');
   console.log(instance2.colors);
   instance2.info();

</script>
</html>